#!/usr/bin/perl

package query_pdb;

use strict;
use warnings;
use LWP::Simple qw( $ua );
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION     = 1.00;
@ISA         = qw(Exporter);
@EXPORT      = ();
@EXPORT_OK   = qw(search_pdb);
%EXPORT_TAGS = ( DEFAULT => [qw(&search_pdb)] );

sub search_pdb {

	my $XML_query = $_[0];
	
	# Create a request                                                                                  
	my $request = HTTP::Request->new( POST => 'http://www.rcsb.org/pdb/rest/search/');
	
	$request->content_type( 'application/x-www-form-urlencoded' );
	
	$request->content( $XML_query );
	
	# Post the XML query                                                                                
	my $response = $ua->request( $request );
		
	# Check to see if there is an error
	unless( $response->is_success ) {
		print "-- Error when querying PDB: ", $response->status_line, "\n";
	}
	
	my @pdb_ids = split(/\n/, $response->content);
	
	return @pdb_ids;
	
}

1;